{extend name="view/base" /}

{block name="head"}
<style type="text/css">
    th, td {
        text-align: center !important;
    }
</style>
{/block}
{block name="main"}

<h1 class="bd-title" id="content">修改数据表</h1>
<hr>

<div id="table_index">
    <form action="" id="table_form" class="row" onsubmit="table.edit_table(event)">
        <div class="form-group col-6">
            <label>分组</label>
            <select class="form-control" name="group_id" v-model="tableForm.group_id" required>
                <option v-for="list in group" :value="list.id">{{list.name}}</option>
            </select>
        </div>
        <div class="form-group col-6">
            <label>模块（数据库）</label>
            <select class="form-control" name="model_id" v-model="tableForm.model_id" required disabled>
                <option v-for="list in model" :value="list.id">{{list.model_name}} （zb_{{list.db_name}}）</option>
            </select>
        </div>
        <div class="form-group col-6">
            <label>数据库引擎</label>
            <select class="form-control" name="engine" v-model="tableForm.engine" required disabled>
                <option v-for="list in engine" :value="list.name">{{list.name}}</option>
            </select>
        </div>
        <div class="form-group col-6">
            <label>负责人</label>
            <select class="form-control" name="person_id" v-model="tableForm.person_id" required>
                <option v-for="list in person" :value="list.id">{{list.name}}</option>
            </select>
        </div>
        <div class="form-group col-6">
            <label>数据表备注</label>
            <input type="text" class="form-control" name="table_title" v-model="tableForm.table_title" placeholder="标题" required>
        </div>
        <div class="form-group col-6">
            <label>数据表名称</label>
            <div class="input-group">
                <div class="input-group-prepend">
                    <div class="input-group-text">tp_</div>
                </div>
                <input type="text" class="form-control" name="table_name" v-model="tableForm.table_name" placeholder="数据表名称" required disabled>
            </div>
        </div>
        <div class="form-group col-6">
            <button type="submit" class="btn btn-outline-primary">修改基本信息</button>
        </div>
    </form>


    <!-- 字段列表 -->
    <div class="row">
        <div class="col-12 mt-3">
            <table class="table table-bordered" id="group_table">
                <thead class="thead-light">
                <tr>
                    <th scope="col">备注</th>
                    <th scope="col">字段</th>
                    <th scope="col">类型</th>
                    <th scope="col">允许空</th>
                    <th scope="col">默认值</th>
                    <th scope="col">枚举注释</th>
                    <th scope="col">操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="(data,index) in fieldForm.field">
                    <td>{{data.comment}}</td>
                    <td>{{data.name}}</td>
                    <td>{{data.type}}({{data.length}})</td>
                    <td>{{data.not_null=='0'?'允许空':'不为空'}}</td>
                    <td>{{data.default==="AUTO_INCREMENT"?'自增长':data.default}}</td>
                    <td>
                        <select v-if="data.enum.length !==0 " class="form-control form-control-sm" name="type">
                            <option v-for="li in data.enum" :value="li.key">{{li.key}} - {{li.name}}</option>
                        </select>
                        <span v-if="data.enum.length === 0">—</span>
                    </td>
                    <td>
                        <span v-if="index === 0">主键</span>
                        <a v-if="index !== 0" :href="'javascript:table.del_field('+data.id+')'">删除</a>
                        <a v-if="index !== 0" :href="'javascript:table.edit_comment_model('+index+')'">修改</a>
                    </td>
                </tr>
                <tr>
                    <td colspan="7">
                        <!-- 添加字段 按钮 -->
                        <button type="button" class="btn btn-light form-control" data-toggle="modal" data-target="#field">+</button>
                        <!-- 添加字段 弹出框 -->
                        <div class="modal fade" id="field" tabindex="-1" role="dialog" aria-labelledby="groupLabel" aria-hidden="true">
                            <div class="modal-dialog modal-dialog-centered" role="document">
                                <div class="modal-content">
                                        <div class="modal-header bg-db text-light">
                                            <h5 class="modal-title" id="groupLabel">添加字段</h5>
                                            <button type="button" class="close text-light" data-dismiss="modal" aria-label="Close">
                                                <span aria-hidden="true">&times;</span>
                                            </button>
                                        </div>
                                        <div class="modal-body text-left">
                                            <form action="" id="addField" onsubmit="table.add_field(event)">
                                                <div class="form-group">
                                                    <label>备注</label>
                                                    <input type="text" class="form-control" name="comment" placeholder="备注" autocomplete="off" required>
                                                </div>
                                                <div class="form-group">
                                                    <label>字段名</label>
                                                    <input type="text" class="form-control" name="name" placeholder="字段名" autocomplete="off" required>
                                                </div>
                                                <div class="form-group">
                                                    <label>类型</label>
                                                    <select class="form-control" v-model="fieldForm.type" name="type" required>
                                                        <option v-for="list in type" :value="list.name">{{list.name}}</option>
                                                    </select>
                                                </div>
                                                <div class="form-group" v-if="fieldForm.type == 'Int'| fieldForm.type == 'VarChar'| fieldForm.type == 'TinyInt'">
                                                    <label>长度</label>
                                                    <input v-for="list in type" v-if="list.name==fieldForm.type" type="text" class="form-control" name="length" placeholder="长度" :value="list.length" autocomplete="off" required>
                                                </div>
                                                <div class="form-group" v-if="fieldForm.type == 'Decimal'">
                                                    <label>长度，小数位数（ , 隔开）</label>
                                                    <input v-for="list in type" v-if="list.name==fieldForm.type" type="text" class="form-control" name="length" placeholder="长度,小数点（ , 隔开）" :value="list.length" autocomplete="off" required>
                                                </div>
                                                <div class="form-group" v-if="fieldForm.type == 'Enum'">
                                                    <label>值</label>
                                                    <input v-for="list in type" v-if="list.name==fieldForm.type" type="text" class="form-control" name="length" placeholder="枚举，用（,）隔开" oninput="table.set_enum()" id="enum" autocomplete="off" required>
                                                </div>
                                                <div class="form-group">
                                                    <label>允许空</label>
                                                    <div class="form-row">
                                                        <div class="col-2">
                                                            <div class="custom-control custom-radio">
                                                                <input type="radio" class="custom-control-input" name="not_null" value="0" id="not_null_true" required>
                                                                <label class="custom-control-label" for="not_null_true">允许</label>
                                                            </div>
                                                        </div>
                                                        <div class="col-3">
                                                            <div class="custom-control custom-radio">
                                                                <input type="radio" class="custom-control-input" name="not_null" value="1" id="not_null_false" required checked>
                                                                <label class="custom-control-label" for="not_null_false">不允许</label>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="form-group" v-if="fieldForm.type !== 'Text'">
                                                    <label>默认值</label>
                                                    <div class="custom-control custom-checkbox mb-3" v-if="fieldForm.type == 'Int'">
                                                        <input type="checkbox" class="custom-control-input" name="default" value="AUTO_INCREMENT" id="auto_increment" onclick="table.default_hidden()">
                                                        <label class="custom-control-label" for="auto_increment">自增长</label>
                                                    </div>
                                                    <input v-for="list in type" type="text" class="form-control" v-if="default_show && fieldForm.type !== 'Enum' && list.name==fieldForm.type" :value="list.default" name="default" placeholder="默认值" autocomplete="off">

                                                    <select v-if="fieldForm.type === 'Enum'" class="form-control" name="default" required>
                                                        <option v-for="list in enum_data" :value="list.name">{{list.name}}</option>
                                                    </select>
                                                </div>
                                                <button id="add_field_submit_btn" type="submit" style="display: none;"></button>
                                            </form>
                                            <div class="mb-3">
                                                <label>枚举注释</label>
                                                <!-- 添加枚举 表单 -->
                                                <form class="form-inline" id="alter_enum" onsubmit="table.alter_enum_add(event)">
                                                    <div class="form-group">
                                                        <input type="text" class="form-control" name="enum_key" placeholder="Key" required autocomplete="off">
                                                        <input type="text" class="form-control ml-2" name="enum_name" placeholder="Name" required autocomplete="off">
                                                    </div>
                                                    <button type="submit" class="btn btn-primary ml-2">添加</button>
                                                </form>
                                            </div>
                                            <table class="table table-bordered">
                                                <thead class="thead-light">
                                                <tr>
                                                    <th scope="col">key</th>
                                                    <th scope="col">value</th>
                                                    <th scope="col">操作</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <tr v-for="(li,index) in temp_enum_form">
                                                    <td>{{li.key}}</td>
                                                    <td>{{li.name}}</td>
                                                    <td><a :href="'javascript:table.alter_enum_del('+index+')'">删除</a></td>
                                                </tr>
                                                <tr v-if="temp_enum_form.length === 0">
                                                    <td colspan="3">无枚举数据</td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                                            <button type="submit" class="btn btn-db" onclick="table.add_field_submit()">添加</button>
                                        </div>
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
        <div>
            <a href="{:url('/generate')}" class="btn btn-primary">返回首页</a>
        </div>
    </div>
    <!--字段同步-->
    <div class="modal fade" id="checkDataModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header bg-warning">
                    <h5 class="modal-title" id="exampleModalLongTitle">字段数据不相同</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <template v-if="check_modal.g_null">
                        <div>“代码生成”缺少数据库中的字段，已自动添加</div>
                    </template>
                    <template v-if="(check_modal.g_null && check_modal.different_field) || (check_modal.g_null && check_modal.d_null)">
                        <hr>
                    </template>
                    <template v-if="check_modal.d_null">
                        <div>
                            <p>“数据库”中缺少字段（<template v-for="(li,index) in check_data.d_null"><template v-if="index!==0">、</template>{{li.name}}</template>）</p>
                            <table class="table table-sm table-bordered">
                                <thead class="thead-dark">
                                <tr>
                                    <th scope="col">来源</th>
                                    <th scope="col">字段</th>
                                    <th scope="col">备注</th>
                                    <th scope="col">字段类型</th>
                                    <th scope="col">长度</th>
                                    <th scope="col">允许空</th>
                                </tr>
                                </thead>
                                <tbody>
                                <template v-for="li in check_data.d_null">
                                    <tr>
                                        <td>代码生成</td>
                                        <td>{{li.name}}</td>
                                        <td>{{li.comment}}</td>
                                        <td>{{li.type}}</td>
                                        <td>{{li.length}}</td>
                                        <td>
                                            <template v-if="li.not_null==0">允许空</template>
                                            <template v-if="li.not_null==1">不为空</template>
                                        </td>
                                    </tr>
                                </template>
                                </tbody>
                            </table>
                            <button type="button" class="btn btn-outline-primary" onclick="table.generate_del_field()">删除字段（代码生成）</button>
                            <button type="button" class="btn btn-db" onclick="table.database_add_field()">添加字段（数据库）</button>
                        </div>
                    </template>
                    <template v-if="check_modal.d_null && check_modal.different_field">
                        <hr>
                    </template>
                    <template v-if="check_modal.different_field">
                        <div>
                            <p>“代码生成”与“数据库”字段信息不相同</p>
                            <table class="table table-sm table-bordered">
                                <thead class="thead-dark">
                                <tr>
                                    <th scope="col">来源</th>
                                    <th scope="col">字段</th>
                                    <th scope="col">备注</th>
                                    <th scope="col">字段类型</th>
                                    <th scope="col">长度</th>
                                    <th scope="col">允许空</th>
                                </tr>
                                </thead>
                                <tbody>
                                <template v-for="(li,index) in check_data.different_field">
                                    <tr :class="{'table-secondary':index%2===1}">
                                        <td>数据库</td>
                                        <td>{{li.database.name}}</td>
                                        <td>{{li.database.comment}}</td>
                                        <td>{{li.database.type}}</td>
                                        <td>{{li.database.length}}</td>
                                        <td>
                                            <template v-if="li.database.not_null==0">允许空</template>
                                            <template v-if="li.database.not_null==1">不为空</template>
                                        </td>
                                    </tr>
                                    <tr :class="{'table-secondary':index%2===1}">
                                        <td>代码生成</td>
                                        <td>{{li.generate.name}}</td>
                                        <td>{{li.generate.comment}}</td>
                                        <td>{{li.generate.type}}</td>
                                        <td>{{li.generate.length}}</td>
                                        <td>
                                            <template v-if="li.generate.not_null==0">允许空</template>
                                            <template v-if="li.generate.not_null==1">不为空</template>
                                        </td>
                                    </tr>
                                </template>
                                </tbody>
                            </table>
                            <button type="button" class="btn btn-outline-primary" onclick="table.generate_edit_field()">修改字段（代码生成）</button>
                            <button type="button" class="btn btn-outline-danger" onclick="table.database_rebuild_field()">删除并重建字段（数据库）</button>
                        </div>
                    </template>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
    <!--修改备注-->
    <div class="modal fade" id="editCommentModal" tabindex="-1" role="dialog" aria-labelledby="editCommentLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header bg-warning">
                    <h5 class="modal-title" id="editCommentLabel">修改</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="form-group row">
                        <label class="col-3 col-form-label">备注</label>
                        <div class="col-9">
                            <input type="text" class="form-control" v-model="edit_field_form.comment">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-3 col-form-label">允许空值</label>
                        <div class="col-9">
                            <div class="row">
                                <div class="col-4">
                                    <div class="custom-control custom-radio">
                                        <input type="radio" v-model="edit_field_form.not_null" class="custom-control-input" value="0" id="not_null_true_edit" required>
                                        <label class="custom-control-label" for="not_null_true_edit">允许</label>
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="custom-control custom-radio">
                                        <input type="radio" v-model="edit_field_form.not_null" class="custom-control-input" value="1" id="not_null_false_edit" required>
                                        <label class="custom-control-label" for="not_null_false_edit">不允许</label>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="table.edit_comment()">修改</button>
                </div>
            </div>
        </div>
    </div>

</div>


{/block}
{block name="footer"}
<script type="text/javascript">
    //数据库表
    const table = new Vue({
        el: '#table_index',
        data: {
            table_id:0,
            tableForm:[],
            fieldForm:{
                type:'VarChar',
                field:[]
            },
            alter_edit_field:{
                enum:[]
            },
            temp_enum_form:[],
            btn: {
                btn_save:true,
            },
            submit_type: undefined,
            enum_modal_id:undefined,
            default_show:true,
            enum_data:[],
            group: [],
            table: [],
            model: [],
            person: [],
            engine: [{'name':'InnoDB'},{'name':'MyISAM'}],
            type: [
                {'name':'VarChar','length':'255','default':''},
                {'name':'Int','length':'10','default':'0'},
                {'name':'TinyInt','length':'2','default':'0'},
                {'name':'Decimal','length':'10,2','default':'0'},
                {'name':'Enum','length':'','default':''},
                {'name':'Text','length':'','default':''},
                {'name':'Date','length':'','default':'0000-00-00'}
            ],
            check_data: {},
            check_modal: {
                d_null: false,
                g_null: false,
                different_field: false
            },
            character_set: [
                {
                    'name':'utf8',
                    'children': ['utf8_general_ci','utf8_unicode_ci']
                },{
                    'name':'gbk',
                    'children': ['gbk_bin','gbk_chinese_ci']
                }
            ],
            edit_field_form: {
                id: 0,
                not_null: 0,
                comment: ''
            }
        },
        created() {
            this.get_table_id();
            this.check_field();
        },
        methods: {
            get_table_id(){
                const that = this;
                if(window.sessionStorage.getItem("table_edit_id") === null){
                    window.location.href="{:url('/generate')}";
                }
                that.table_id = window.sessionStorage.getItem("table_edit_id");
            },
            get_list() {
                const that = this;
                that.get_table_info();
                that.get_field_list();

                $.ajax({
                    url:"{:url('/generate/Api/get_model_list')}",
                    type:"GET",
                    async:true,
                    success:function (res) {
                        if (res.status){
                            that.model = res.data;
                        }else{
                            that.model = [];
                        }
                    },
                });
                $.ajax({
                    url:"{:url('/generate/Api/get_group_list')}",
                    type:"GET",
                    async:true,
                    success:function (res) {
                        if (res.status){
                            that.group = res.data;
                        }else{
                            that.group = [];
                        }
                    },
                });
                $.ajax({
                    url:"{:url('/generate/Api/get_person_list')}",
                    type:"GET",
                    async:true,
                    success:function (res) {
                        if (res.status){
                            that.person = res.data;
                        }else{
                            that.person = [];
                        }
                    },
                });

                $.ajax({
                    url:"{:url('/generate/Api/get_table_list')}",
                    type:"GET",
                    async:true,
                    success:function (res) {
                        if (res.status){
                            that.table = res.data;
                        }else{
                            that.table = [];
                        }
                    },
                });
            },
            check_field(){
                const that = this;
                $('#checkDataModal').modal('hide');
                $.ajax({
                    url:"{:url('/generate/Index/check_field')}",
                    type:"POST",
                    data:{
                        table_id:that.table_id
                    },
                    async:true,
                    success:function (res) {
                        if (res.status){
                            Vue.set(that,'check_data',res.data);
                            Vue.set(that.check_modal,'g_null',false);
                            Vue.set(that.check_modal,'d_null',false);
                            Vue.set(that.check_modal,'different_field',false);

                            if (res.data.g_null.length!==0 || res.data.d_null.length!==0 || res.data.different_field.length!==0){
                                $('#checkDataModal').modal('show')
                            }
                            if (res.data.g_null.length!==0){
                                Vue.set(that.check_modal,'g_null',true);
                                that.get_list();
                            }
                            if (res.data.d_null.length!==0){
                                Vue.set(that.check_modal,'d_null',true);
                            }
                            if (res.data.different_field.length!==0){
                                Vue.set(that.check_modal,'different_field',true);
                            }
                        }
                    }
                });
                that.get_list();
            },
            database_add_field(){
                const that = this;
                $.ajax({
                    url:"{:url('/generate/Index/add_field_to_database')}",
                    type:"POST",
                    data:{
                        table_id:that.table_id,
                        field_list: that.check_data.d_null
                    },
                    async:true,
                    success:function (res) {
                        if (res.status){
                            that.check_field();
                        }else{
                            alert(res.msg);
                        }
                    }
                });
            },
            generate_del_field(){
                const that = this;
                $.ajax({
                    url:"{:url('/generate/Index/delete_field_list')}",
                    type:"POST",
                    data:{
                        field_list: that.check_data.d_null
                    },
                    async:true,
                    success:function (res) {
                        if (res.status){
                            that.check_field();
                        }else{
                            alert(res.msg);
                        }
                    }
                });
            },
            database_rebuild_field(){
                const that = this;
                $.ajax({
                    url:"{:url('/generate/Index/database_rebuild_field')}",
                    type:"POST",
                    data:{
                        table_id:that.table_id,
                        field_list: that.check_data.different_field
                    },
                    async:true,
                    success:function (res) {
                        if (res.status){
                            that.check_field();
                        }else{
                            alert(res.msg);
                        }
                    }
                });
            },
            generate_edit_field(){
                const that = this;
                $.ajax({
                    url:"{:url('/generate/Index/generate_edit_field')}",
                    type:"POST",
                    data:{
                        table_id:that.table_id,
                        field_list: that.check_data.different_field
                    },
                    async:true,
                    success:function (res) {
                        if (res.status){
                            that.check_field();
                        }else{
                            alert(res.msg);
                        }
                    }
                });
            },
            edit_comment_model(index){
                const that = this;
                Vue.set(that.edit_field_form,'id',that.fieldForm.field[index].id);
                Vue.set(that.edit_field_form,'comment',that.fieldForm.field[index].comment);
                Vue.set(that.edit_field_form,'not_null',that.fieldForm.field[index].not_null);
                $('#editCommentModal').modal('show');
            },
            edit_comment(){
                const that = this;
                $.ajax({
                    url:"{:url('/generate/Index/edit_field_comment')}",
                    type:"POST",
                    data:{
                        id:that.edit_field_form.id,
                        not_null:that.edit_field_form.not_null,
                        comment:that.edit_field_form.comment
                    },
                    async:true,
                    success:function (res) {
                        if (res.status){
                            alert('修改成功！');
                        }else{
                            alert('修改失败！');
                        }
                    },
                });
                $('#editCommentModal').modal('hide');
                that.get_field_list();
            },
            get_table_info(){
                const that = this;
                $.ajax({
                    url:"{:url('/generate/Api/get_table_info')}",
                    type:"POST",
                    data:{
                        id:that.table_id
                    },
                    async:true,
                    success:function (res) {
                        if (res.status){
                            that.tableForm = res.data;
                        }else{
                            that.tableForm = [];
                        }
                    },
                });
            },
            get_field_list(){
                const that = this;
                $.ajax({
                    url:"{:url('/generate/Api/get_field_list')}",
                    type:"POST",
                    data:{
                        id:that.table_id
                    },
                    async:true,
                    success:function (res) {
                        if (res.status){
                            that.fieldForm.field = res.data;
                        }else{
                            that.fieldForm.field = [];
                        }
                    },
                });
            },
            del_field(id){
                if (confirm("是否要删除这个字段？")){
                    const that = this;
                    $.ajax({
                        url:"{:url('/generate/Api/delete_field')}",
                        type:"POST",
                        data:{
                            'id': id
                        },
                        async:true,
                        success:function (res) {
                            if (res.status){
                                that.get_field_list();
                            }else{
                                alert(res.msg);
                            }
                        }
                    });
                }
            },
            alter_enum_del(id){
                Vue.delete(this.temp_enum_form,id);
            },
            alter_enum_add(event){
                event.preventDefault();
                const form_data = $('#alter_enum').serializeArray();
                const data = {};
                for(let i in form_data){
                    data[form_data[i]['name']]=form_data[i]['value'];
                }
                const res = {};
                res['key'] = data['enum_key'];
                res['name'] = data['enum_name'];
                const length = Object.keys(this.temp_enum_form).length;
                Vue.set(this.temp_enum_form,length,res);

                $('#alter_enum')[0].reset();
            },
            add_field_submit(id){
                $('#add_field_submit_btn').click();
            },
            add_field(event){
                event.preventDefault();
                const that = this;
                const form_data = $('#addField').serializeArray();
                const data = {};
                for(let i in form_data){
                    data[form_data[i]['name']]=form_data[i]['value'];
                }
                data['table_id']=that.table_id;
                data['enum']=JSON.stringify(that.temp_enum_form);
                $.ajax({
                    url:"{:url('/generate/Api/alter_table_add')}",
                    type:"POST",
                    data:data,
                    async:true,
                    success:function (res) {
                        if (res.status){
                            that.temp_enum_form=[];
                            $('#addField')[0].reset();
                            $('#field').modal('hide');
                            that.get_field_list();
                            alert(res.msg);
                        }else{
                            alert(res.msg);
                        }
                    }
                });

            },
            default_hidden(){
                if($('#auto_increment').prop("checked")){
                    Vue.set(this,'default_show',false);
                }else{
                    Vue.set(this,'default_show',true);
                }
            },
            set_enum(){
                const data = $('#enum').val();
                const enum_data = data.split(",");
                const res = [];
                for (const i in enum_data) {
                    res.push({'name':enum_data[i]})
                }
                Vue.set(this,'enum_data',res);
            },
            set_enum_id(id){
                Vue.set(this,'enum_modal_id',id);
                $('#enumModal').modal('show')
                console.log(this.enum_modal_id);
            },
            edit_table(event){
                event.preventDefault();
                const that = this;
                //获取表单数据
                const data = {
                    'id':that.table_id,
                    'group_id':that.tableForm.group_id,
                    'person_id':that.tableForm.person_id,
                    'table_title':that.tableForm.table_title
                };

                $.ajax({
                    url:"{:url('/generate/api/edit_table')}",
                    type:"POST",
                    data:data,
                    async:true,
                    success:function (res) {
                        if (res.status){
                            alert(res.msg);
                        }else{
                            that.get_list();
                            alert(res.msg);
                        }
                    },
                })

            }
        }
    })


</script>
{/block}